import { Elysia } from "elysia";
import { swagger } from '@elysiajs/swagger'
import { html } from '@elysiajs/html'
import db from "./utils/db";
import { logger } from "@tqman/nice-logger";
import * as api from './api'
const FrontTheme = 'default'
const AdminTheme = 'default'
import * as front from './front/default'
import * as admin from './admin/default'

import {staticPlugin}  from '@elysiajs/static'
 

const app = new Elysia()
  .decorate(() => {
    return {
      db
    }
  })
  .use(staticPlugin({
    assets:`src/front/${FrontTheme}/static`,
    prefix:`/front/${FrontTheme}/static`,
  }))
  .use(staticPlugin({
    assets:`src/admin/${AdminTheme}/static`,
    prefix:`/admin/${AdminTheme}/static`,
  }))
  .use(logger({
    mode: 'live',
    withTimestamp: true
  }))
  .use(swagger({scalarCDN:'https://unpkg.com/@scalar/api-reference@1.13.10/dist/browser/standalone.js'}))
  .use(html())
  .listen(3000);


 



Object.values(api).forEach(a => { 
  Object.values(a).forEach((b) => {
    app.group('/api', _app => _app.use(b))
  })
})


Object.values(front).forEach(a => { 
  Object.values(a).forEach((b) => { 
    app.use(b)
  })
})

Object.values(admin).forEach(a => { 
  Object.values(a).forEach((b) => { 
    app.group('/admin', _app => _app.use(b))
  })
})
 




console.log(
  `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);

export type ElysiaApp = typeof app
